﻿using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class JsonHelper {

    public static string ToJsonString(object obj) {
        return JsonConvert.SerializeObject(obj);
    }

	public static T ParseObject<T>(string json) where T : class {
        JsonSerializer serializer = new JsonSerializer();
        StringReader sr = new StringReader(json);
        object o = serializer.Deserialize(new JsonTextReader(sr), typeof(T));
        T t = o as T;
        return t;
    }

    public static T LoadObject<T>(string path) where T : class {
        TextAsset textAsset = Resources.Load<TextAsset>(path);
        return ParseObject<T>(textAsset.ToString());
    }
}
